package com.chanyachting.emall.util;

import javax.servlet.http.HttpServletRequest;

import com.chanyachting.emall.servlet.PicCheckCode;



/****
 * 图形验证码工具类
 * @author robert
 *
 */
public class ImageCodeUtil {
	
	
	private HttpServletRequest request;
	
	
	public ImageCodeUtil(HttpServletRequest request){
		
		this.request=request;
		
	}
	
	
	public String getImageCode(){
		
		if(request.getSession ().getAttribute (PicCheckCode.CODE_IN_SESSION)!=null){
			
			return (String)request.getSession ().getAttribute (PicCheckCode.CODE_IN_SESSION);
		}
		
		return "";
	}
	
	
	/****
	 * 验证用户输入的图形验证码
	 * @param code
	 * @return
	 */
	public boolean checkImageCode(String code){
		
		String imageCode=this.getImageCode();
		
		if(imageCode.trim().length()>0){
			
			if(code!=null && code.trim().length()>0 && code.equals(imageCode)){
				
				return true;
			}
			
		}
		
		return false;
	}

}
